type ClassValue = string | number | boolean | undefined | null;
type ClassMapping = Record<string, unknown>;
type ClassArray = ClassValue[];

export function classnames(...args: (ClassValue | ClassMapping | ClassArray)[]): string {
    const classes: string[] = [];

    for (const arg of args) {
        if (!arg) continue;

        if (typeof arg === 'string') {
            classes.push(arg);
        } else if (Array.isArray(arg)) {
            classes.push(classnames(...arg));
        } else if (typeof arg === 'object') {
            for (const key in arg) {
                if (Object.prototype.hasOwnProperty.call(arg, key) && arg[key]) {
                    classes.push(key);
                }
            }
        }
    }

    return classes.filter(Boolean).join(' ');
}